﻿using System;
using System.Drawing;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Controls game menu.  This class adds additional screens to the main stack based on user options. 
	/// </summary>
	class MenuScreen : Screen
	{
		private readonly Menu menu;

		public MenuScreen()
		{
			menu = new Menu();
			//Setup one panel to fill screen
			PanelList.Add(new Panel(new Point(4, 3),
				Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));

			SetupMenu();
		}

		void SetupMenu()
		{
			menu.Add(new MenuItem(Properties.Strings.StartGame, SelectNewGame));
			menu.Add(new MenuItem(Properties.Strings.EnterSeed, SelectSeed));
			menu.Add(new MenuItem(Properties.Strings.SelectLanguage, SelectLanguage));
			menu.Add(new MenuItem(Properties.Strings.Exit, SelectExit));
		}

		#region Methods

		public override void Show()
		{
			Draw();
			while (active)
			{
				if (menu.HandleInput())
					menu.DrawMenu(PanelList[0]);
			}
		}

		void Draw()
		{
			Clear();
			PanelList[0].Draw();
			menu.DrawMenu(PanelList[0]);
		}

		//Event method
		void SelectNewGame(object sender, EventArgs e)
		{
			GameManager.Instance.ScreenStack.Push(new DungeonScreen());
			active = false;
		}
		//Event method
		void SelectSeed(object sender, EventArgs e)
		{
			GameManager.Instance.ScreenStack.Push(new SeedScreen());
			active = false;
		}
		//Event method
		void SelectLanguage(object sender, EventArgs e)
		{
			new LanguageScreen().Show();
			Clear();
			PanelList[0].Draw();
		}
		//Event method
		static void SelectExit(object sender, EventArgs e)
		{
			GameManager.Instance.Exit();
		}

		#endregion
	}
}
